package com.shuai.shuaisecondhand_springboot.service;

import com.shuai.shuaisecondhand_springboot.entity.Goods;
import com.shuai.shuaisecondhand_springboot.mapper.GoodsMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;


    //查询
    public List<Goods> findAll() {
        return goodsMapper.findAll();
    }

    //根据Uid查询数据
    public List<Goods> getUidGoods(String Uid, String status, String name) {
        return goodsMapper.getUidGoods(Uid, status, name);
    }

    //根据id查找所有数据
    public Goods findOne(@Param("Gid") Integer Gid) {
        return goodsMapper.findOne(Gid);
    }

    //插入
    public Boolean insertGoods(Goods goods) {
        try {
            return goodsMapper.insertGoods(goods);
        } catch (Exception e) {
            return false;
        }
    }

    //修改商品状态
    public Boolean updateGoodsStatus(String id, String status) {
        try {
            return goodsMapper.updateGoodsStatus(id, status);
        } catch (Exception e) {
            return false;

        }

    }

    //管理员修改
    public Boolean updateGoods(Goods goods) {
        try {
            return goodsMapper.updateGoods(goods);
        } catch (Exception e) {
            return false;

        }

    }

    //用户用户修改
    public Boolean updateUserGoods(Goods goods) {
        try {
            return goodsMapper.updateUserGoods(goods);
        } catch (Exception e) {
            return false;

        }

    }

    //删除
    public Integer deleteGoods(long id) {
        return goodsMapper.deleteGoods(id);
    }

    //批量删除
    public Integer deleteGoodsBatch(List<Integer> Gids) {
        return goodsMapper.deleteGoodsBatch(Gids);
    }

    //用户分页查询
    public List<Goods> getGoodsPage(Integer pageNum, Integer pageSize, String name) {
        return goodsMapper.getGoodsPage(pageNum, pageSize, name);
    }

    //查询Uid的所有数据量
    public int getUidTotal(String Uid, String status, String name) {
        return goodsMapper.getSidTotal(Uid, status, name);
    }

    //查询所有数据量
    public int getTotal(String name) {
        return goodsMapper.getTotal(name);
    }

    //查询商品总数
    public int getAllTotal() {
        return goodsMapper.getAllTotal();
    }

    //管理员分页查询
    public List<Goods> getAdminGoodsPage(Integer pageNum, Integer pageSize, String name) {
        return goodsMapper.getAdminGoodsPage(pageNum, pageSize, name);
    }

    //管理员查询所有数据量
    public int getAdminTotal(String name) {
        return goodsMapper.getAdminTotal(name);
    }
}
